package com.alan.blue;




import org.junit.jupiter.api.Test;

import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import java.io.DataOutputStream;

/**
 * 一个蓝牙通信的简易例子
 * @Auther: Alan liu
 * @Date: 2018/11/26 17:16
 * @Description: BlueMain
 */
public class BlueMain{

    @Test
    public  void startServer() {
        BluetoothService bluetoothServic = new BluetoothService();
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        bluetoothServic.stop();
    }

    @Test
    public void sendMsg(){
        try {
            String url = "btspp://2400BA731B3A:9;authenticate=false;encrypt=false;master=false";
            StreamConnection streamConnection = (StreamConnection) Connector.open(url);
            DataOutputStream dos = streamConnection.openDataOutputStream();
            dos.write("hello".getBytes());
            dos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

